<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
	String id = request.getParameter("id");//用request得到
	System.out.print("------->"+id); 
	request.setCharacterEncoding("utf-8");
	response.setCharacterEncoding("utf-8");
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
	<head>
		<base href="<%=basePath%>">

		<title></title>
		<meta http-equiv="pragma" content="no-cache">
		<meta http-equiv="cache-control" content="no-cache">
		<meta http-equiv="expires" content="0">
		<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
		<meta http-equiv="description" content="This is my page">
		<!-- 配置文件 -->
		<script type="text/javascript" charset="utf-8"
			src="ueditor/ueditor.config.js">
		</script>
		<!-- 编辑器源文件 -->
		<script type="text/javascript" charset="utf-8"
			src="ueditor/ueditor.all.min.js">
		</script>
		<!--建议手动加在语言，避免在ie下有时因为加载语言失败导致编辑器加载失败-->
		<!--这里加载的语言文件会覆盖你在配置项目里添加的语言类型，比如你在配置项目里配置的是英文，这里加载的中文，那最后就是中文-->
		<script type="text/javascript" charset="utf-8"
			src="ueditor/lang/zh-cn/zh-cn.js"> 
		</script>
		<script type="text/javascript" charset="utf-8"
			src="ueditor/jquery-3.3.1.min.js"> 
			</script>
		 
		<!-- 默认样式 -->
		<link type="text/css" href="ueditor/themes/default/css/ueditor.css"
			rel="stylesheet" />
	</head>

	<body>


		<form id="formid" name="myform" method='post' onsubmit="return sub();">
			<input type="hidden" name="rewardId" id="rewardId"   />
			标题：
			<input type="text" name="reward_title" id="reward_title"  style="width:400px; " />
			<br />
			内容：
			<textarea name="content" id="content"></textarea>

			<input type="submit" value="提交" class="update-button" />

		</form>

		<!-- 实例化编辑器 -->
		<script type="text/javascript">
			var ue = UE.getEditor("content");
		</script>
	</body>
	
	<script type="text/javascript">
	$(document).ready(function(){
		 var json = {
		        "rewardId": "<%=id%>" 
		    };
		    
			$.ajax({
		        type: "POST",
		        url: "https://yuyue.rainbowsystem.cn:8680/rainbowdb/reward/getRewardById",
		        contentType: "application/json; charset=utf-8",
		        data: JSON.stringify(json),
		        dataType: "json",
		        success: function (message) {
		        	if(message['success']==true){
		        		var data=message['data'];
		        		  
		        		var reward_title=data[0]['reward_title'];
		        		var reward_content=data[0]['reward_content'];
		        		var rewardId=data[0]['_id'];
		        		  
		        		$("#rewardId").val(rewardId);
		        		$("#reward_title").val(reward_title);
		        		var editor = UE.getEditor("content");
		        		editor.setContent(""+reward_content);
		        	}  
		        },
		        error: function (message) {
		        	  
		        }
		    });
	    		
	});
	
		//提交更新
 		function sub(){
 			 
		    var editor = UE.getEditor("content");
			var reward_title=$("#reward_title").val();
			var rewardId=$("#rewardId").val();
			var reward_content=editor.getContent();
			
			if(reward_title==""){
				alert("标题不能为空");
				return false;
			}
			if(reward_content==""){
				alert("内容不能为空");
				return false;
			}
			
			var json = {
				"rewardId":rewardId,
		        "reward_title": reward_title,
		        "reward_content": reward_content 
		    };
		    
			$.ajax({
		        type: "POST",
		        url: "https://yuyue.rainbowsystem.cn:8680/rainbowdb/reward/updateReward",
		        contentType: "application/json; charset=utf-8",
		        data: JSON.stringify(json),
		        dataType: "json",
		        success: function (message) {
		        	alert("更新成功");
		        },
		        error: function (message) {
		        	alert("更新数据不成功"+message); 
		        }
		    });
		    
		    return false;
		}
	</script>
	
	<style type=text/css>
	
	.reward_title{
		width: 300px;
	}
	
	.update-button { /* 按钮美化 */
		width: 270px; /* 宽度 */
		height: 40px; /* 高度 */
		border-width: 0px; /* 边框宽度 */
		border-radius: 3px; /* 边框半径 */
		background: #1E90FF; /* 背景颜色 */
		cursor: pointer; /* 鼠标移入按钮范围时出现手势 */
		outline: none; /* 不显示轮廓线 */
		font-family: Microsoft YaHei; /* 设置字体 */
		color: white; /* 字体颜色 */
		font-size: 17px; /* 字体大小 */
		margin-top: 12px;
		
	}
	.update-button:hover { /* 鼠标移入按钮范围时改变颜色 */
		background: #5599FF;
	 }
	</style>
</html>
